package com.gopay.webtest.controller.cloud;

import com.gopay.webtest.controller.base.BaseController;
import com.gopay.webtest.handler.cloud.TransCloudSignHandler;
import com.gopay.webtest.util.DateUtils;
import com.gopay.webtest.vo.cloud.Cloud0620Vo;
import com.gopay.webtest.xml.XmlDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

/**
 * 云账户 卡信息管理
 * www.gopay.com.cn Inc.All rights reserved.
 */
@RequestMapping("/cloud/cardInfoManager")
@Controller
public class CardInfoManageController extends BaseController {

    @Resource(name = "xmlDao")
    private XmlDao xmlDao;

    @Resource(name="transCloudSignHandler")
    private TransCloudSignHandler transCloudSignHandler;


    @RequestMapping("/applyCharge")
    public ModelAndView applyCharge() {
        ModelAndView mv = new ModelAndView();

        try {
            Map<String, String> map = xmlDao.readData4Map("cloud_apply", "cardInfoManager");
            map.put("reqTime", DateUtils.format(new Date(), "yyyyMMddHHmmss"));
            map.put("merOrderNum", System.currentTimeMillis()+"");
            mv = new ModelAndView("cloud.charge.cardInfoManager");
            mv.addObject("config", map);
            this.logger.info("^^^^^^^^^^^^^^^^^云平台卡信息管理页面初始化成功^^^^^^^^^^^^^^^^^");
        } catch (Exception e) {
            logger.error("跳转页面", e);
        }
        return mv;
    }

    @RequestMapping("/doApply")
    public ModelAndView doApply(@ModelAttribute Cloud0620Vo cloud0620Vo) {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("cloud.charge.doCardInfoManager");
        try {
            // 签名
            transCloudSignHandler.sign(cloud0620Vo.getTranCode()+"_"+cloud0620Vo.getVersion(), "signType", "signValue", cloud0620Vo, getRequest());
            this.logger.info("^^^^^^^^^^^^^^^^^云平台卡信息管理页面签名成功^^^^^^^^^^^^^^^^^");

            mv.addObject("cloud0620Vo", cloud0620Vo);
        } catch (Exception e) {
            logger.error("执行申请", e);
        }
        return mv;
    }


}
